package com.pt.pok.proxy.client.integration.util.net;

import com.pt.pok.model.ClassIds;

import java.nio.ByteBuffer;

import static com.pt.pok.proxy.client.integration.util.zip.CompressionUtil.decompress;

/**
 * @author Roman.Ivanov@playtech.com
 *         <p/>
 *         Aware of underlying network message format
 */
public class BinaryFormatUtility {

    public static boolean isCompressedData(ByteBuffer networkMessage) {
        return true;
    }

    // compressed
    public static byte[] getRawData(ByteBuffer networkMessage) {
        return networkMessage.array();
    }

    // decompressed
    public static byte[] getReadyData(ByteBuffer networkMessage) {
        return isCompressedData(networkMessage) ? decompress(getRawData(networkMessage)) : getRawData(networkMessage);
    }

    public static int getClassId(ByteBuffer networkMessage) {
        return ClassIds.LOGIN_REQUEST.getId();
    }

    public static ByteBuffer buildNetworkMessage(boolean setLength, boolean isCompressed, int classId, byte[] data) {
        return ByteBuffer.allocate(data.length).put(data);
    }

}
